<template>
  <view class="main">
    <template v-if="addressList.length > 0">
      <view class="addressBox" v-for="(item, index) in addressList" :key="index">
        <view class="nameBox">
          <view class="nBox">{{ item[0][0] }}</view>
          <view class="nameInfo">
            <view class="f">
              <text>{{ item[0] }}</text>
              {{ item[1] }}
            </view>
            <view class="s">{{ item[2] }}</view>
          </view>
        </view>
        <view class="mrdzBox">
          <u-radio-group v-model="item[3]" v-if="item[3] === true">
            <u-radio label="默认地址" :name="true" activeColor="#2ccf97"></u-radio>
          </u-radio-group>
          <view v-else></view>
          <!-- <u-icon name="edit-pen" color="#BFBFBF" size="25" @click="goPage(item)"></u-icon> -->
        </view>
      </view>
    </template>
    <u-empty mode="list" v-else></u-empty>
    <!-- <view class="bottomBox">
      <u-button text="添加地址" @click="goPage" color="#2ccf97"></u-button>
    </view> -->
  </view>
</template>

<script setup lang="ts">
import { onBeforeMount, ref } from "vue";
import { getInfo } from "../../api/home";
import { useStore } from "../../stores/counter";
const addressList = ref<any[]>([]);
onBeforeMount(async () => {
  const phone = uni.getStorageSync("userInfo")[0][4];
  console.log(phone);
  const res = await getInfo({
    FormId: "BD_CommonContact",
    Data: {
      FieldKeys: "FName,FMobile,FBizAddress,FIsDefaultConsignee",
      FilterString: [{ Left: "(", FieldName: "FMobile", Compare: "=", Value: phone, Right: ")", Logic: "AND" }],
      OrderString: "",
      TopRowCount: 0,
      StartRow: 0,
      Limit: 2000,
      SubSystemId: "",
      FormId: "BD_CommonContact",
    },
  });
  addressList.value = res;
});
const goPage = (item?: any) => {
  useStore().setEditAddressInfo(item);
  uni.redirectTo({
    url: `/pages/myPage/addAddress`,
  });
};
</script>

<style lang="less" scoped>
.main {
  padding-top: 20rpx;
  padding-bottom: 110rpx;
}
.addressBox {
  background: #ffffff;
  border-radius: 16rpx;
  padding: 32rpx;
  margin-bottom: 20rpx;
  .nameBox {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f7f7f7;
    padding-bottom: 34rpx;
    .nBox {
      width: 64rpx;
      height: 64rpx;
      background: #2ccf97;
      border-radius: 50%;
      margin-right: 24rpx;
      text-align: center;
      line-height: 64rpx;
      font-size: 28rpx;
      color: #fff;
    }
    .nameInfo {
      .f {
        font-size: 28rpx;
        font-weight: 500;
        color: #333333;
        line-height: 36rpx;
        text {
          margin-right: 24rpx;
        }
      }
      .s {
        font-size: 26rpx;
        color: #bebebe;
        line-height: 36rpx;
        margin-top: 8rpx;
      }
    }
  }
  .mrdzBox {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20rpx;
  }
}
</style>
